<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/bootstrap-responsive.css">
    <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/style.css">
    
<link type="text/css" href="/ncrm/Public/Admin/css/b5m-plugin.css" rel="stylesheet">
<link type="text/css" href="/ncrm/Public/Admin/css/b5m.css" rel="stylesheet"></head>
<body>
  <?php if(session('roleid')==1 || session('roleid')==0 || session('roleid')==2 ||session('roleid')==3||session('roleid')==4){?>

	<ul>
		<li>
		<h5>查询部门资源使用情况:</h5>
		<div style="margin-left: 25px">
		<input class="Wdate" id="firstdate" onfocus="WdatePicker({isShowClear:false,readOnly:true})" type="text">至<input class="Wdate" id="seconddate" onfocus="WdatePicker({isShowClear:false,readOnly:true})" type="text">&nbsp;&nbsp;

<!--     <select name="group.gid" id="groupid">
   			<option selected="selected" value="-1">分组</option>
	    		<?php if(is_array($group)): $i = 0; $__LIST__ = $group;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><option value="<?php echo ($r["gid"]); ?>"><?php echo ($r["gname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
	</select> -->

	<?php if(session('roleid')==0){ ?>
	<select  id="groupid">
   			<option value="-1">分区</option>
	    		<option value="1" <?php if($buid == 1): ?>selected<?php endif; ?> >一区</option>
	    		<option value="2" <?php if($buid == 2): ?>selected<?php endif; ?> >二区</option>
	    		<option value="3" <?php if($buid == 3): ?>selected<?php endif; ?> >三区</option>
	</select>

	<select  id="buid">
   				<option value="-1">分部</option>
	    		<option value="1" <?php if($quid == 1): ?>selected<?php endif; ?> >一部</option>
	    		<option value="2" <?php if($quid == 2): ?>selected<?php endif; ?> >二部</option>
	    		<option value="3" <?php if($quid == 3): ?>selected<?php endif; ?> >三部</option>
	</select>

	<select  id="zuid">
   			<option value="-1">分组</option>
	    		<option value="1" <?php if($zuid == 1): ?>selected<?php endif; ?> >一组</option>
	    		<option value="2" <?php if($zuid == 2): ?>selected<?php endif; ?> >二组</option>
	    		<option value="3" <?php if($zuid == 3): ?>selected<?php endif; ?> >三组</option>
	</select>

	<select  id="duiid">
   			<option value="-1">分队</option>
	    		<option value="1" <?php if($duiid == 1): ?>selected<?php endif; ?> >一队</option>
	    		<option value="2" <?php if($duiid == 2): ?>selected<?php endif; ?> >二队</option>
	    		<option value="3" <?php if($duiid == 3): ?>selected<?php endif; ?> >三队</option>
	</select>

	<?php } ?>



	<?php if(session('roleid')==1){ ?>
	<select  id="groupid">
   				<option value="-1">分部</option>
	    		<option value="1" <?php if($buid == 1): ?>selected<?php endif; ?> >一部</option>
	    		<option value="2" <?php if($buid == 2): ?>selected<?php endif; ?> >二部</option>
	    		<option value="3" <?php if($buid == 3): ?>selected<?php endif; ?> >三部</option>
	</select>
	<select  id="zuid">
   			<option value="-1">分组</option>
	    		<option value="1" <?php if($zuid == 1): ?>selected<?php endif; ?> >一组</option>
	    		<option value="2" <?php if($zuid == 2): ?>selected<?php endif; ?> >二组</option>
	    		<option value="3" <?php if($zuid == 3): ?>selected<?php endif; ?> >三组</option>
	</select>
	<select  id="duiid">
   			<option value="-1">分队</option>
	    		<option value="1" <?php if($duiid == 1): ?>selected<?php endif; ?> >一队</option>
	    		<option value="2" <?php if($duiid == 2): ?>selected<?php endif; ?> >二队</option>
	    		<option value="3" <?php if($duiid == 3): ?>selected<?php endif; ?> >三队</option>
	</select>

	<?php } ?>




	<?php if(session('roleid')==2){ ?>
	<select  id="groupid">
   			<option value="-1">分组</option>
	    		<option value="1" <?php if($buid == 1): ?>selected<?php endif; ?> >一组</option>
	    		<option value="2" <?php if($buid == 2): ?>selected<?php endif; ?> >二组</option>
	    		<option value="3" <?php if($buid == 3): ?>selected<?php endif; ?> >三组</option>
	</select>
	<select  id="duiid">
   			<option value="-1">分队</option>
	    		<option value="1" <?php if($duiid == 1): ?>selected<?php endif; ?> >一队</option>
	    		<option value="2" <?php if($duiid == 2): ?>selected<?php endif; ?> >二队</option>
	    		<option value="3" <?php if($duiid == 3): ?>selected<?php endif; ?> >三队</option>
	</select>
	<?php } ?>




	<?php if(session('roleid')==3){ ?>
	<select  id="groupid">
   			<option value="-1">分组</option>
	    		<option value="1" <?php if($buid == 1): ?>selected<?php endif; ?> >一队</option>
	    		<option value="2" <?php if($buid == 2): ?>selected<?php endif; ?> >二队</option>
	    		<option value="3" <?php if($buid == 3): ?>selected<?php endif; ?> >三队</option>
	</select>
	<?php } ?>
		<input class="btn btn-primary" value="查询" onclick="query()" type="button">
		</div>
		<table class="table table-bordered table-hover definewidth m10">
    <thead>
  				<tr align="center"><td>未使用资源数量</td><td>申请未通过资源数量</td><td>已通过资源数量</td><td>意向资源数量</td><td>已入金资源数量</td><td>非微信号码数量</td></tr>
  				</thead>
				<tbody><tr align="center">
				<td><?php echo ($resCount[0]); ?></td>
				<td><?php echo ($resCount[1]); ?></td>
				<td><?php echo ($resCount[2]); ?></td>
				<td><?php echo ($resCount[3]); ?></td>
				<td><?php echo ($resCount[4]); ?></td>
				<td><?php echo ($resCount[5]); ?></td>
				</tr>
    </tbody></table>
		</li>
		<li><h5>根据资源号码查询员工:</h5>
		<div style="margin-left: 25px"><input id="pnumberid" placeholder="请输入资源号码" maxlength="11">&nbsp;&nbsp;<input class="btn btn-primary" value="查询员工" onclick="queryEmployee()" type="button"></div>
		<table class="table table-bordered table-hover definewidth m10" id="userinfo">
		<thead><tr><td>资源号码</td><td>所属部门</td><td>所属分组</td><td>所属员工</td><td>操作时间</td><td>使用状态</td></tr></thead>
    </table>
		</li>
	</ul>

<?php } ?>


 <?php if(session('roleid')==5){?>
<table class="table table-bordered table-hover definewidth m10">
	<tbody><tr><td>资源使用情况查询：</td></tr>
			<tr>
			<td>
			<select id="check" name="sid" style="float:left" onchange="test('check')">
  					<option value="-1">请选择</option>
  					<option value="1" <?php if($zz == 1): ?>selected<?php endif; ?>>申请未通过</option>
  					<option value="2" <?php if($zz == 2): ?>selected<?php endif; ?>>已通过</option>
  					<option value="3" <?php if($zz == 3): ?>selected<?php endif; ?>>意向客户</option>
  					<option value="4" <?php if($zz == 4): ?>selected<?php endif; ?>>已入金</option>
  					<option value="5" <?php if($zz == 5): ?>selected<?php endif; ?>>非微信号码</option>
  			</select>
  				<div id="childselectcheck" style="display:none;float:left">
  					<select name="sid" id="myresourceidcheck">
  						<option selected="selected" value="-1">请选择</option>
  						<option value="6" <?php if($zz == 6): ?>selected<?php endif; ?>>A类意向客户</option>
  						<option value="7" <?php if($zz == 7): ?>selected<?php endif; ?>>B类意向客户</option>
  						<option value="8" <?php if($zz == 8): ?>selected<?php endif; ?>>C类意向客户</option>
  						<option value="9" <?php if($zz == 9): ?>selected<?php endif; ?>>D类意向客户</option>
  					</select>
  				</div>
			<input value="查询" onclick="check()" class="btn btn-primary" type="button">
			</td>
			</tr>
			</tbody></table>
  	<table class="table table-bordered table-hover definewidth m10">
  			<tbody>
  				<tr align="center">
  				    <td>资源号码</td>
  				     <td width="100px">状态</td>
  				     <td width="440px">修改状态下拉列表</td>
  				     <td width="150px">资源备注</td>
  				     <td width="120px">更新时间</td>
  				     <td width="60px">操作</td>
  				    </tr>
  		     <?php if(is_array($resourceInfo1)): $i = 0; $__LIST__ = $resourceInfo1;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><tr>
  				<td><span id="pnumber126345"><?php echo ($r["pnumber"]); ?></span><!-- <input value="复制" class="btn btn-primary" onclick="copy2Clip(126345)" type="button"> -->
  				</td>
  				<td>
  				 <?php if($r["sid"] == 0): ?>未使用<?php endif; ?>
  				 <?php if($r["sid"] == 1): ?>申请未通过<?php endif; ?>
  				 <?php if($r["sid"] == 2): ?>已通过<?php endif; ?>
  				 <?php if($r["sid"] == 4): ?>已入金<?php endif; ?>
  				 <?php if($r["sid"] == 5): ?>非微信号码<?php endif; ?>
  				 <?php if($r["sid"] == 6): ?>A类意向客户<?php endif; ?>
                 <?php if($r["sid"] == 7): ?>B类意向客户<?php endif; ?>
  				 <?php if($r["sid"] == 8): ?>C类意向客户<?php endif; ?>
  				 <?php if($r["sid"] == 9): ?>D类意向客户<?php endif; ?>
  				</td>
  				<td>
  				   <select id="<?php echo ($r["id"]); ?>" name="sid" style="float:left" onchange="test(<?php echo ($r["id"]); ?>)">
  					<option selected="selected" value="-1">请选择</option>
  					<option value="1">申请未通过</option>
  					<option value="2">已通过</option>
  					<option value="3">意向客户</option>
  					<option value="4">已入金</option>
  					<option value="5">非微信号码</option>
  				  </select>
  				<div id="childselect<?php echo ($r["id"]); ?>" style="display:none;float:left">
  					<select name="sid" id="myresourceid<?php echo ($r["id"]); ?>">
  						<option selected="selected" value="-1">请选择</option>
  						<option value="6">A类意向客户</option>
  						<option value="7">B类意向客户</option>
  						<option value="8">C类意向客户</option>
  						<option value="9">D类意向客户</option>
  					</select>
  				</div>
  		        </td>
  		          
  		        <td>
  		        <input id="wechatname<?php echo ($r["id"]); ?>" type="text" value="<?php echo ($r["wechatname"]); ?>">
  		        </td>

  		        <td>
  		        <?php echo (date('Y-m-d H:i',$r["updatetime"])); ?>
  		        </td>

  		        <td>
  		        <a href="javascript:update(<?php echo ($r["id"]); ?>)" style="text-decoration: NONE" class="btn btn-primary">提交</a>
  		        </td>
  		   </tr><?php endforeach; endif; else: echo "" ;endif; ?>
  	  </tbody></table>
  	  <input type="hidden" value="<?php echo $sid;?>" id='sid'>
  	    <div class="inline  page" style="text-align: center;">

         <?php echo $count1;?> 条记录 <?php echo $page1 ;?>/<?php echo $resPage1 ;?>页 
	　<a style="margin-right: -10px;" href="javascript:upPage(<?php echo $page1;?>)">上一页</a>
	　<span style="color:red"><?php echo $page1;?></span>
   　　<a style="margin-left: -20px;" href="javascript:nextPage(<?php echo $page1;?>,<?php echo $resPage1;?>)">下一页</a>
       &nbsp;&nbsp;&nbsp;跳转到第<input id="toPage" style="width:30px;height:20px;padding-top: 4px;" type="text">页
        <a href="javascript:toGoPage(<?php echo $resPage1;?>)">跳转</a>
    　</div> 
  	<?php } ?>		
　　
</body>
<script type="text/javascript" src="/ncrm/Public/Admin/js/jquery.js"></script>
    <!--<script type="text/javascript" src="Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="/ncrm/Public/Admin/js/bootstrap.js"></script>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/ckform.js"></script>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/common.js"></script>
    <script type="text/javascript" src="/ncrm/Public/DatePicker/WdatePicker.js"></script><link type="text/css" rel="stylesheet" href="/ncrm/Public/DatePicker/skin/WdatePicker.css">
	<script type="text/javascript">
		function query(){
			var first = $("#firstdate").val();
			var groupid=$("#groupid").val();
			var zuid = $('#zuid').val();
			var buid = $('#buid').val();
			var duiid = $('#duiid').val();

			if(first=='' && groupid== -1){
				alert('请选择至少一个查询条件');
				return false;
			}

			
			var second = $("#seconddate").val();
			var firstdate = first.split("-");
			var firstyear = firstdate[0];
			var firstmonth = firstdate[1];
			var firstday = firstdate[2];
			var firsttime = firstyear + firstmonth + firstday;
			var seconddate = second.split("-");
			var secondyear = seconddate[0];
			var secondmonth = seconddate[1];
			var secondday = seconddate[2];
			var secondtime = secondyear + secondmonth + secondday;
			if(firsttime>secondtime){
				alert("查询的开始日期应小于结束日期");
				return;
			}

			window.location.href="zysyqk?groupId="+groupid+"&zuid="+zuid+"&duiid="+duiid+"&buid="+buid;

		}
		function queryEmployee(){
			var pnumber = $("#pnumberid").val();
			var a = $("#pnumberid").val();


			if(pnumber==""){
				alert("请输入要查询的号码");
				return;
			}
			if(isNaN(pnumber)){
				alert("请输入正确的资源号码");
				return;
			}
               $.ajax({
              type: 'POST',
              url: "<?php echo U('Zygl/checkYuangong');?>",
              data: {"pnumber":pnumber,},
              dataType : "json", 
              success: function(data) {
                 if(data.ok==0){
						alert("该资源不存在,请重新输入");
						$("#pnumberid").val("");
						return;
					}else if(data.ok==1){
						alert("管理员尚未分配该资源,如需帮助请联系管理员");
						return;
					}else if(data.ok==2){
						alert(data.depar+"经理尚未分配该资源,如需帮助请联系经理");
					}else{
					var department = data.department;
					var group = data.group;
					var username = data.username;
					var statusname;
					if(data.status==0){
                        statusname = '未使用';
					}
					if(data.status==1){
                        statusname = '申请未通过';
					}
					if(data.status==2){
                       statusname = '已通过';
					}
					if(data.status==6 || data.status==7 || data.status==8 || data.status==9){
						statusname = '意向客户';
					}
					if(data.status==4){
						statusname = '已入金';
					}
					if(data.status==5){
						statusname = '非微信号码';
					}
					
					var time = data.updatetime;
					var pnumber = data.pnumber;
					var html = "<tr><td>"+pnumber+"</td><td>"+department+"</td><td>"+group+"</td><td>"+username+"</td><td>"+time+"</td><td>"+statusname+"</td></tr>";
					$("#userinfo").append(html);
					}
                }
              }) 
		}

		function test(obj){
		var statusid = $("#"+obj+"").val();
		if(statusid==3){
			$("#childselect"+obj+"").show();
		}else{
			$("#childselect"+obj+"").hide();
		}
	}

	function update(obj){
			var resourceid = obj;	
			var statusid=$("#"+obj+"").val();
			if(statusid==3){
				statusid=$("#myresourceid"+obj+"").val();
			}
			var wechatname = $("#wechatname"+obj+"").val();
			if(statusid!=6){
				if(wechatname==""){
				alert("请输入资源备注");
				return ;
				}
			}
			if(statusid==-1){
				alert("请选择资源状态");
				return ;
			}

			var run = confirm("是否更新资源?");
			if(run){
            $.ajax({
              type: 'POST',
              url: "<?php echo U('Zygl/update');?>",
              data: {"resourceId":resourceid,"statusId":statusid,"wechatName":wechatname},
              dataType : "json",
              success: function(data){
                 if(data.ok==1){
                     alert("修改成功");
                     window.location.reload();
                     var statusid=$("#"+obj+"").val(-1);
                  }
                  if(data.ok==2){
                  	 alert("修改失败");
                     window.location.reload();
                     var statusid=$("#"+obj+"").val(-1);
                  }
                }
              })
			}
		}

		function check(){
			var sid = $('#check').val();
			if(sid == -1){
				alert('请选择需求查询的条件！');
				return false;
			}
			if(sid==3){
				sid=$("#myresourceidcheck").val();
			}
			window.location.href="zysyqk?statusId="+sid; 
	}

	function upPage(page){
		var sid = $('#sid').val();
		if(page==1){
			alert('已经是第一页了');
		}else{
			page--;
		}
		window.location.href="zysyqk?page="+page+"&statusId="+sid;
       
	}
	function nextPage(page,pa){
        var sid = $('#sid').val();
		if(page==pa){
			alert('已经是最后一页了');
		}else{
			page++;
		}
		window.location.href="zysyqk?page="+page+"&statusId="+sid;
       
	}
	function toGoPage(pa){
		var sid = $('#sid').val();
		var page = $('#toPage').val();
		if(page>pa){
			alert('页数为'+pa+'页，请核对输入页数！');
			return;
		}
		if(isNaN(page)){
			alert('请输入数字');
			exit;
		}
		window.location.href="zysyqk?page="+page+"&statusId="+sid;
	}
	</script>
<script src="/ncrm/Public/Admin/js/b5m.js" charset="utf-8" id="b5mmain" type="text/javascript"></script>
</html>